const KoaRouter = require('koa-router')
const HttpClient = require('../util/HttpClient')
const Template = require('../util/Template')

const router = new KoaRouter();
const modules = require('../../modules');

/* 呼叫中心报表 */
router.get('/stats/callcenter/new', async ctx => {
  let modConfig = modules['report.callcenter'];
  let script = ['/report.callcenter.js'];
    
  ctx.body = await Template.renderWithData('呼叫中心报表', {}, script, modConfig.template, ctx)
});

/* 客户报表 */
router.get('/stats/customer/new', async ctx => {
  let modConfig = modules['report.customer'];
  let script = ['/report.customer.js'];
      
  ctx.body = await Template.renderWithData('客户报表', {}, script, modConfig.template, ctx)
});

/* 备件报表 */
router.get('/stats/part', async ctx => {
  let modConfig = modules['report.part'];
  let script = ['/report.part.js'];
        
  ctx.body = await Template.renderWithData('备件报表', {}, script, modConfig.template, ctx)
});

/* 服务项目报表 */
router.get('/stats/service', async ctx => {
  let modConfig = modules['report.service'];
  let script = ['/report.service.js'];
          
  ctx.body = await Template.renderWithData('服务项目报表', {}, script, modConfig.template, ctx)
});

/* 人员报表 */
router.get('/stats/staff/new', async ctx => {
  let modConfig = modules['report.staff'];
  let script = ['/report.staff.js'];
            
  ctx.body = await Template.renderWithData('人员报表', {}, script, modConfig.template, ctx)
});
/* 服务台报表 */
router.get('/stats/station/new', async ctx => {
  let modConfig = modules['report.station'];
  let script = ['/report.station.js'];
              
  ctx.body = await Template.renderWithData('服务台报表', {}, script, modConfig.template, ctx)
});
/* 工单报表 */
router.get('/stats/task/new', async ctx => {
  let modConfig = modules['report.task'];
  let script = ['/report.task.js'];
                
  ctx.body = await Template.renderWithData('工单报表', {}, script, modConfig.template, ctx)
});
/* 统计报表 */
router.get('/stats/statistics', async ctx => {
  let modConfig = modules['report.statistics'];
  let script = ['/report.statistics.js'];
                  
  ctx.body = await Template.renderWithData('统计报表', {}, script, modConfig.template, ctx)
});

/* 业务计划 */
router.get('/stats/plan/new', async ctx => {
  let modConfig = modules['report.plan'];
  let script = ['/report.plan.js'];
                    
  ctx.body = await Template.renderWithData('业务计划', {}, script, modConfig.template, ctx)
});

/* 人员效率统计 */
router.get('/stats/staffEfficiency', async ctx => {
  let modConfig = modules['report.staffEfficiency'];
  let script = ['/report.staffEfficiency.js'];
                      
  ctx.body = await Template.renderWithData('人员效率统计', {}, script, modConfig.template, ctx)
});

/* 自定义报表 */
router.get('/stats/customReport', async ctx => {
  let modConfig = modules['report.customReport'];
  let script = ['/report.customReport.js'];
  
  ctx.body = await Template.renderWithData('', {}, script, modConfig.template, ctx)
});

/* 系统报表 */
router.get('/stats/system', async ctx => {
  let modConfig = modules['report.system'];
  let script = ['/report.system.js'];
    
  ctx.body = await Template.renderWithData('', {}, script, modConfig.template, ctx)
});

/* 产品报表 */
router.get('/stats/product', async ctx => {
  let modConfig = modules['report.product'];
  let script = ['/report.product.js'];
    
  ctx.body = await Template.renderWithData('', {}, script, modConfig.template, ctx)
});

/* 业务报表 */
router.get('/stats/business', async ctx => {
  let modConfig = modules['report.business'];
  let script = ['/report.business.js'];
    
  ctx.body = await Template.renderWithData('', {}, script, modConfig.template, ctx)
});
/* 业务报表-日历 */
router.get('/stats/calendar', async ctx => {
  let modConfig = modules['report.calendar'];
  let script = ['/report.calendar.js'];
    
  ctx.body = await Template.renderWithData('', {}, script, modConfig.template, ctx)
});
/* 仓库报表 */
// router.get('/stats/sparepart/showStatistics', async ctx => {
//   let modConfig = modules['report.sparepart.showStatistics'];
//   let script = ['/report.sparepart.showStatistics.js'];
    
//   let { url, headers} = ctx.request;
//   let result = await HttpClient.request(url, 'get', null, { headers });
//   let body = result.body;
  
//   ctx.body = await Template.renderWithHtmlForPart('仓库报表', body, script, modConfig.template, ctx);
// });

/* 智能报表主页面 */
router.get('/stats/intelligenceReport/index', async ctx => {
  let modConfig = modules['report.index'];
  let script = ['/report.index.js'];
    
  ctx.body = await Template.renderWithData('智能报表', {}, script, modConfig.template, ctx)
});

/* 管理报表主页面 */
router.get('/stats/intelligenceReport/management', async ctx => {
  let modConfig = modules['report.management'];
  let script = ['/report.management.js'];
    
  ctx.body = await Template.renderWithData('管理报表', {}, script, modConfig.template, ctx)
});

/* 管理报表图表页 */
router.get('/stats/intelligenceReport/charts', async ctx => {
  let modConfig = modules['report.charts'];
  let script = ['/report.charts.js'];
    
  ctx.body = await Template.renderWithData('', {}, script, modConfig.template, ctx)
});

/* 相关新版本合并自定义报表 有paas  */
router.get('/stats/customReportAggregate', async ctx => {
  let modConfig = modules['report.customReportAggregate'];
  let script = ['/report.customReportAggregate.js'];

  ctx.body = await Template.renderWithData('', {}, script, modConfig.template, ctx)
});

/* 管理报表图表页 */
router.get('/stats/beiJiData', async ctx => {
  let modConfig = modules['report.beiji'];
  let script = ['/report.beiji.js'];
    
  ctx.body = await Template.renderWithData('', {}, script, modConfig.template, ctx)
});
module.exports = router;
